<template>
	<view class="log">
		<Navbar>账房</Navbar>
		<scroll-view scroll-x class="scroll_box">
			<view class="item" :class="active==item.key?'active':''" v-for="(item,index) in scroll"
				@click="changeActive(item.key)">
				{{item.title}}
			</view>
		</scroll-view>
		<view class="content">
			<view class="title">
				<view class="time">时间</view>
				<view>数量</view>
				<view>状态</view>
			</view>
			<scroll-view scroll-y class="scroll_view" @scrolltolower="loadmore">
				<view class="list">
					<view class="item" v-for="item in list">
						<!-- <view class="item" v-for="item in list" @click="router(`/pages/common/order_deta?id=${item.id}`)"> -->
						<view class="time">{{item.created_at}}</view>
						<view>{{item.value}}</view>
						<view>{{item.type_name}}</view>
					</view>
				</view>
				<u-loadmore :status="loadmore_status" :color="$store.state.loadmoreColor"
					:lineColor="$store.state.loadmoreColor" line @loadmore="loadmore" />
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		orderLists,
		userLog
	} from '@/request/api.js';
	export default {
		data() {
			return {
				active: "",
				scroll: [],
				list: []
			}
		},
		async onLoad() {
			let {
				list,
				user_balance_field
			} = await userLog({
				page: this.page,
				limit: this.limit
			});
			this.scroll = user_balance_field;

			this.active = user_balance_field.length ? user_balance_field[0].key : "";

			this.last_page = list.last_page;
			list = list.list;
			this.list = this.page == 1 ? list : [...this.list, ...list];
			this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
		},
		methods: {
			async getList() {
				let {
					list
				} = await userLog({
					page: this.page,
					limit: this.limit,
					field: this.active
				});
				this.last_page = list.last_page;
				list = list.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			// async getList() {
			// 	let {
			// 		list
			// 	} = await orderLists({
			// 		page: this.page,
			// 		limit: this.limit
			// 	});
			// 	this.last_page = list.last_page;
			// 	list = list.list;
			// 	this.list = this.page == 1 ? list : [...this.list, ...list];
			// 	this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			// },
			loadmore() {
				if (this.page < this.last_page) {
					this.page++;
					this.getList();
				}
			},
			changeActive(value) {
				this.active = value;
				this.page = 1;
				this.list = [];
				this.getList();
			}
		}
	}
</script>

<style scoped lang="scss">
	.log {
		height: 100vh;
		background: #29170D;
		overflow: hidden;

		.scroll_box {
			height: 100rpx;
			line-height: 100rpx;
			padding-bottom: 20rpx;
			padding-left: 20rpx;
			box-sizing: border-box;
			background-color: rgba(31, 11, 5, 0.6);
			white-space: nowrap;

			.item {
				display: inline-block;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 40rpx;
				font-weight: 400;
				font-family: LiSu;
				padding: 0 35rpx;

				&.active {
					color: #494338;
					background: url(#{$baseImageUrl}/common/active.png) no-repeat;
					background-size: 100% 100%;
				}

				&:last-child {
					margin: 0;
				}
			}
		}

		.content {
			height: calc(100vh - #{$navbarHeight} - 100rpx);
			padding: 90rpx 50rpx 40rpx;
			box-sizing: border-box;
			background: url(#{$baseImageUrl}/my/bg2.png) no-repeat;
			background-size: 100% 100%;

			.title {
				height: 60rpx;
				display: flex;
				justify-content: space-between;

				view {
					flex: 1;
					text-align: center;
					color: #494338;
					font-size: 28rpx;
					font-weight: 400;
					font-family: SimSun;

					&.time {
						flex: 2;
					}
				}
			}

			.scroll_view {
				height: calc(100% - 60rpx);

				.list {
					.item {
						height: 58rpx;
						margin-bottom: 10rpx;
						background: url(#{$baseImageUrl}/my/item.png) no-repeat;
						background-size: 100% 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						view {
							flex: 1;
							text-align: center;
							color: #494338;
							font-size: 26rpx;
							font-weight: 400;
							font-family: SimSun;

							&.time {
								flex: 2;
							}
						}
					}
				}
			}
		}
	}
</style>